<template>
            <el-collapse-item title="多点选择页面" name="selectitem">
                <div style="margin-top: 30px;">多个数据点：</div>

                <div
                    v-for="(item, index) in curComponent.hg3000.linkids"
                    :key="index"
                    class="list"
                    @click=""
                >
                    <span>{{ item.descr }}</span>
                    <div class="icon-container">
                        <span class="iconfont icon-shanchu" @click="deleteItem(index)"></span>
                        <span class="iconfont icon-shangyi" @click="moveUp(index)"></span>
                        <span class="iconfont icon-xiayi" @click="moveDown(index)"></span>
                        <span class="iconfont icon-bianji" @click="editItem(index)"></span>
                    </div>
                </div>

                <el-button  @click="insertItem">添加点</el-button>
                <DlgSelectItem  ref="refselectitem"  :dialog-visible="dlgVisible"  @res-select-item="handleSelectItem"  ></DlgSelectItem>
                
            </el-collapse-item>
</template>

<script>
import { mapState } from 'vuex'

import DlgSelectItem from './DlgSelectItem.vue';

export default {
    components: { DlgSelectItem },
    data() {
        return {
            dlgVisible: false ,
            isInsert: true ,
            edtIndex: -1, 
            
        }
    },
    computed: mapState([
        'curComponent',
    ]),
    methods: {
        insertItem(  ){
            this.isInsert = true 
            this.dlgVisible = true 
        },
        handleSelectItem( code , result ){
            if( code == 1 ) {
                if( this.isInsert )
                    this.curComponent.hg3000.linkids.push(  JSON.parse( JSON.stringify(result)  ) )
                else{
                    this.curComponent.hg3000.linkids.splice(  this.edtIndex,  1, JSON.parse( JSON.stringify(result) ))
                }
            }
            this.dlgVisible = false
        },
        moveUp( index ){
            if(index === 0 ) return
            let obj  = this.curComponent.hg3000.linkids[index]
            this.curComponent.hg3000.linkids.splice( index, 1 )
            this.curComponent.hg3000.linkids.splice( index-1, 0, obj )

        },

        moveDown( index ){
            if(index === this.curComponent.hg3000.linkids.length - 1 ) return
            let obj  = this.curComponent.hg3000.linkids[index]
            this.curComponent.hg3000.linkids.splice( index, 1 )
            this.curComponent.hg3000.linkids.splice( index+1, 0, obj )
        },

        deleteItem( index ){
            this.curComponent.hg3000.linkids.splice(  index, 1 )
        },

        editItem( index ){
            this.isInsert = false
            this.edtIndex = index
            this.$refs.refselectitem.init( this.curComponent.hg3000.linkids[index] )
            this.dlgVisible = true
            // this.curComponent.hg3000.linkids[index]
        },
        
    },
}
</script>

<style lang="scss" scoped>
.clsOneDot {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.clsOneDot span {
    width: 250px;
    text-align: left;
    margin-left: 20px;
}

.list {
        height: 30px;
        cursor: grab;
        text-align: center;
        color: #333;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 12px;
        padding: 0 10px;
        position: relative;
        user-select: none;

        .icon-container {
            .iconfont {
                cursor: default;
                font-size: 24px;
            }
        }
}

::v-deep( .el-collapse-item__header ){

  background-color: lightgray;
}
</style>
